package com.jose.photogallery;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class ErrorServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {
		
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		
		if (user != null){
			String logoutUrl = userService.createLogoutURL("/");
			req.setAttribute("logoutUrl", logoutUrl);
			req.setAttribute("user", user);
		} else {
			String loginUrl = userService.createLoginURL("/");
			req.setAttribute("loginUrl", loginUrl);
		}
		
		req.setAttribute("error", "Please Upload only photos (jpeg, png, gif, tiff, ico, bmp)");
		req.getRequestDispatcher("/WEB-INF/JSP/errorpage.jsp").forward(req, resp);
	}
}
